package training.osms.view;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

@ManagedBean
public class OsmsUtil {

	public static final Severity INFO = FacesMessage.SEVERITY_INFO;
	
	public int getNumOfMessages(){
		FacesContext context = FacesContext.getCurrentInstance();
		return context.getMessageList().size();
	}
	public boolean getHasMessages(){
		FacesContext context = FacesContext.getCurrentInstance();
		return context.getMessageList().size() > 0;
	}
	
	public static void sendMessage(String textMessage, Severity level) {
		FacesMessage message = new FacesMessage();
		message.setSeverity(level);
		message.setSummary(textMessage);
		FacesContext context = FacesContext.getCurrentInstance();
		context.addMessage(null, message);		
	}
	
	
}
